<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="中文名称" prop="chineseName">
        <el-input
          v-model="queryParams.chineseName"
          placeholder="请输入中文名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="英文名称-图谱" prop="englishNameKg">
        <el-input
          v-model="queryParams.englishNameKg"
          placeholder="请输入英文名称-图谱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="英文名称" prop="englishName">
        <el-input
          v-model="queryParams.englishName"
          placeholder="请输入英文名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="国别" prop="nationality">
        <el-input
          v-model="queryParams.nationality"
          placeholder="请输入国别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所涉领域" prop="fieldOfInterest">
        <el-input
          v-model="queryParams.fieldOfInterest"
          placeholder="请输入所涉领域"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发布机构" prop="issuingInstitution">
        <el-input
          v-model="queryParams.issuingInstitution"
          placeholder="请输入发布机构"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发布具体机构-图谱" prop="specificIssuingInstitutionKg">
        <el-input
          v-model="queryParams.specificIssuingInstitutionKg"
          placeholder="请输入发布具体机构-图谱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发布具体机构" prop="specificIssuingInstitution">
        <el-input
          v-model="queryParams.specificIssuingInstitution"
          placeholder="请输入发布具体机构"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item label="定位/层级" prop="classification">
        <el-input
          v-model="queryParams.classification"
          placeholder="请输入定位/层级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类别属性-图谱" prop="issueReasonKg">
        <el-input
          v-model="queryParams.issueReasonKg"
          placeholder="请输入类别属性-图谱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类别属性" prop="issueReason">
        <el-input
          v-model="queryParams.issueReason"
          placeholder="请输入类别属性"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:doctrine:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:doctrine:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:doctrine:remove']"
        >删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="doctrineList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键ID" align="center" prop="id" />
      <el-table-column label="中文名称-图谱"   show-overflow-tooltip  align="center" prop="chineseNameKg" />
      <el-table-column label="中文名称"   show-overflow-tooltip   align="center" prop="chineseName" />
      <el-table-column label="英文名称-图谱"    show-overflow-tooltip  align="center" prop="englishNameKg" />
      <el-table-column label="英文名称"   show-overflow-tooltip   align="center" prop="englishName" />
      <el-table-column label="国别"   show-overflow-tooltip   align="center" prop="nationality" />
      <el-table-column label="所涉领域"   show-overflow-tooltip   align="center" prop="fieldOfInterest" />
      <el-table-column label="发布机构"    show-overflow-tooltip   align="center" prop="issuingInstitution" />
      <el-table-column label="发布具体机构-图谱"   show-overflow-tooltip   align="center" prop="specificIssuingInstitutionKg" />
      <el-table-column label="发布具体机构"   show-overflow-tooltip   align="center" prop="specificIssuingInstitution" />
      <el-table-column label="发布时间-图谱"   show-overflow-tooltip   align="center" prop="releaseDateKg" />
      <el-table-column label="发布时间"   show-overflow-tooltip   align="center" prop="releaseDate" />
      <el-table-column label="文件页数"   show-overflow-tooltip   align="center" prop="filePageCount" />
      <el-table-column label="字数"  show-overflow-tooltip    align="center" prop="level" />
      <el-table-column label="定位/层级"  show-overflow-tooltip   align="center" prop="classification" />
      <el-table-column label="命令密级 / 版本"  show-overflow-tooltip   align="center" prop="commandVersion" />
      <el-table-column label="摘要" align="center"  show-overflow-tooltip   prop="summary" />
      <el-table-column label="文件内容目录"   show-overflow-tooltip  align="center" prop="contentDirectory" />
      <el-table-column label="类别属性-图谱"   show-overflow-tooltip  align="center" prop="issueReasonKg" />
      <el-table-column label="类别属性"   show-overflow-tooltip  align="center" prop="issueReason" />
      <el-table-column label="关键词"   show-overflow-tooltip  align="center" prop="keywords" />
      <el-table-column label="历史版本情况"   show-overflow-tooltip  align="center" prop="historicalContext" />
<!--      <el-table-column label="${comment}" align="center" prop="allInfo" />-->
      <el-table-column label="操作"  fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:doctrine:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:doctrine:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改理论法规对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="中文名称-图谱" prop="chineseNameKg">
          <el-input v-model="form.chineseNameKg" placeholder="请输入中文名称-图谱" />
        </el-form-item>
        <el-form-item label="中文名称" prop="chineseName">
          <el-input v-model="form.chineseName" placeholder="请输入中文名称" />
        </el-form-item>
        <el-form-item label="英文名称-图谱" prop="englishNameKg">
          <el-input v-model="form.englishNameKg" placeholder="请输入英文名称-图谱" />
        </el-form-item>
        <el-form-item label="英文名称" prop="englishName">
          <el-input v-model="form.englishName" placeholder="请输入英文名称" />
        </el-form-item>
        <el-form-item label="国别" prop="nationality">
          <el-input v-model="form.nationality" placeholder="请输入国别" />
        </el-form-item>
        <el-form-item label="所涉领域" prop="fieldOfInterest">
          <el-input v-model="form.fieldOfInterest" placeholder="请输入所涉领域" />
        </el-form-item>
        <el-form-item label="发布机构" prop="issuingInstitution">
          <el-input v-model="form.issuingInstitution" placeholder="请输入发布机构" />
        </el-form-item>
        <el-form-item label="发布具体机构-图谱" prop="specificIssuingInstitutionKg">
          <el-input v-model="form.specificIssuingInstitutionKg" placeholder="请输入发布具体机构-图谱" />
        </el-form-item>
        <el-form-item label="发布具体机构" prop="specificIssuingInstitution">
          <el-input v-model="form.specificIssuingInstitution" placeholder="请输入发布具体机构" />
        </el-form-item>
        <el-form-item label="发布时间-图谱" prop="releaseDateKg">
          <el-input v-model="form.releaseDateKg" placeholder="请输入发布时间-图谱" />
        </el-form-item>
        <el-form-item label="发布时间" prop="releaseDate">
          <el-input v-model="form.releaseDate" placeholder="请输入发布时间" />
        </el-form-item>
        <el-form-item label="文件页数" prop="filePageCount">
          <el-input v-model="form.filePageCount" placeholder="请输入文件页数" />
        </el-form-item>
        <el-form-item label="字数" prop="level">
          <el-input v-model="form.level" placeholder="请输入字数" />
        </el-form-item>
        <el-form-item label="定位/层级" prop="classification">
          <el-input v-model="form.classification" placeholder="请输入定位/层级" />
        </el-form-item>
        <el-form-item label="命令密级 / 版本" prop="commandVersion">
          <el-input v-model="form.commandVersion" placeholder="请输入命令密级 / 版本" />
        </el-form-item>
        <el-form-item label="摘要" prop="summary">
          <el-input v-model="form.summary" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="文件内容目录" prop="contentDirectory">
          <el-input v-model="form.contentDirectory" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="类别属性-图谱" prop="issueReasonKg">
          <el-input v-model="form.issueReasonKg" placeholder="请输入类别属性-图谱" />
        </el-form-item>
        <el-form-item label="类别属性" prop="issueReason">
          <el-input v-model="form.issueReason" placeholder="请输入类别属性" />
        </el-form-item>
        <el-form-item label="关键词" prop="keywords">
          <el-input v-model="form.keywords" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="历史版本情况" prop="historicalContext">
          <el-input v-model="form.historicalContext" type="textarea" placeholder="请输入内容" />
        </el-form-item>
<!--        <el-form-item label="${comment}" prop="allInfo">-->
<!--          <el-input v-model="form.allInfo" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
      </el-form>

      <el-form ref="formfj" label-width="120px">
        <el-form-item label="图片" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'image'"
              table-type="2"
              :biz-type="'download'"
              :limit="1"
              style="margin-left: 20px"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>
      <el-form ref="formfj" label-width="120px">
        <el-form-item label="原文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz001'"
              table-type="2"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>

      <el-form ref="formfj" label-width="120px">
        <el-form-item label="译文文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz002'"
              table-type="2"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
            ></FileUpload>
          </div>
        </el-form-item>

      </el-form>
      <el-form ref="formfj" label-width="120px">
        <el-form-item label="精翻文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz003'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="2"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDoctrine, getDoctrine, delDoctrine, addDoctrine, updateDoctrine } from "@/api/business/doctrine";
import FileUpload from '@/components/fileUpload_neww.vue'
import Pictures from '@/components/Pictures'
import { guid } from '@/utils/utils'
export default {
  name: "Doctrine",
  components: { FileUpload },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 理论法规表格数据
      doctrineList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        chineseNameKg: null,
        chineseName: null,
        englishNameKg: null,
        englishName: null,
        nationality: null,
        fieldOfInterest: null,
        issuingInstitution: null,
        specificIssuingInstitutionKg: null,
        specificIssuingInstitution: null,
        releaseDateKg: null,
        releaseDate: null,
        filePageCount: null,
        level: null,
        classification: null,
        commandVersion: null,
        summary: null,
        contentDirectory: null,
        issueReasonKg: null,
        issueReason: null,
        keywords: null,
        historicalContext: null,
        allInfo: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        chineseName: [
          { required: true, message: "中文名称不能为空", trigger: "blur" }
        ],
        englishName: [
          { required: true, message: "英文名称不能为空", trigger: "blur" }
        ],
        nationality: [
          { required: true, message: "国别不能为空", trigger: "blur" }
        ],
        fieldOfInterest: [
          { required: true, message: "所涉领域不能为空", trigger: "blur" }
        ],
        issuingInstitution: [
          { required: true, message: "发布机构不能为空", trigger: "blur" }
        ],
        specificIssuingInstitution: [
          { required: true, message: "发布具体机构不能为空", trigger: "blur" }
        ],
        releaseDate: [
          { required: true, message: "发布时间不能为空", trigger: "blur" }
        ],
        filePageCount: [
          { required: true, message: "文件页数不能为空", trigger: "blur" }
        ],
        level: [
          { required: true, message: "字数不能为空", trigger: "blur" }
        ],
        classification: [
          { required: true, message: "定位/层级不能为空", trigger: "blur" }
        ],
        commandVersion: [
          { required: true, message: "命令密级 / 版本不能为空", trigger: "blur" }
        ],
        issueReason: [
          { required: true, message: "类别属性不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询理论法规列表 */
    getList() {
      this.loading = true;
      listDoctrine(this.queryParams).then(response => {
        this.doctrineList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        chineseNameKg: null,
        chineseName: null,
        englishNameKg: null,
        englishName: null,
        nationality: null,
        fieldOfInterest: null,
        issuingInstitution: null,
        specificIssuingInstitutionKg: null,
        specificIssuingInstitution: null,
        releaseDateKg: null,
        releaseDate: null,
        filePageCount: null,
        level: null,
        classification: null,
        commandVersion: null,
        summary: null,
        contentDirectory: null,
        issueReasonKg: null,
        issueReason: null,
        keywords: null,
        historicalContext: null,
        allInfo: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加理论法规";

      let mizId = guid().replace(/-/g, '');
      this.form.id = mizId
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDoctrine(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改理论法规";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDoctrine(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDoctrine(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除理论法规编号为"' + ids + '"的数据项？').then(function() {
        return delDoctrine(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/doctrine/export', {
        ...this.queryParams
      }, `doctrine_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
